﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Windows.Media;

namespace WpfConsole.ConsoleTest
{
    [TestFixture]
    public class VisualGridTest
    {
        [Test]
        public void TestVisual_SamePosReturnSameVisual()
        {
            VisualGrid grid = CreateGrid();
            Visual first = grid.Visual(5, 5);
            Visual second = grid.Visual(5, 5);
            Assert.AreEqual(first, second);
        }

        private static VisualGrid CreateGrid()
        {
            VisualGrid grid = new VisualGrid(new VisualCollection(new DrawingVisual()));
            return grid;
        }

        [Test]
        public void TestResize_SameSize_RemoveNothing()
        {
            VisualGrid grid = CreateGrid();
            Visual first = grid.Visual(5, 5);
            grid.Resize(6, 6);

            Visual second = grid.Visual(5, 5);
            Assert.AreEqual(first, second);
        }

        [Test]
        public void TestResize_Shrink_RemoveOutsize()
        {
            VisualGrid grid = CreateGrid();
            Visual cell55 = grid.Visual(5, 5);
            Visual cell45 = grid.Visual(4, 5);
            Visual cell54 = grid.Visual(5, 4);
            grid.Resize(4, 4);

            Visual second55 = grid.Visual(5, 5);
            Visual second45 = grid.Visual(4, 5);
            Visual second54 = grid.Visual(5, 4);
            Assert.AreNotEqual(cell55, second55);
            Assert.AreNotEqual(cell45, second45);
            Assert.AreNotEqual(cell54, second54);
        }

        [Test]
        public void TestResize_Widen_RemoveNothing()
        {
            VisualGrid grid = CreateGrid();
            Visual first = grid.Visual(5, 5);
            grid.Resize(7, 7);

            Visual second = grid.Visual(5, 5);
            Assert.AreEqual(first, second);
        }

        [Test]
        public void TestVisual_GetOne_VisualCollecitonCountOne()
        {
            VisualCollection col = CreateVisualCollection();
            VisualGrid grid = new VisualGrid(col);

            Visual vis = grid.Visual(3, 3);
            Assert.AreEqual(1, col.Count);
        }

        private static VisualCollection CreateVisualCollection()
        {
            VisualCollection col = new VisualCollection(new DrawingVisual());
            return col;
        }

        [Test]
        public void TestResize_Shrink_VisualCollecitonCountShrink()
        {
            VisualCollection col = new VisualCollection(new DrawingVisual());
            VisualGrid grid = new VisualGrid(col);

            Visual vis = grid.Visual(3, 3);
            grid.Resize(1, 1);
            Assert.AreEqual(0, col.Count);
        }
    }
}
